package com.jkgl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jkgl.common.core.domain.R;
import com.jkgl.common.utils.SecurityUtils;
import com.jkgl.entity.ChatHistory;
import com.jkgl.service.IChatHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author w020304m
 * @since 2025-05-11
 */
@RestController
@RequestMapping("/chatHistory")
@RequiredArgsConstructor
public class ChatHistoryController {
    private final IChatHistoryService chatHistoryService;


    @GetMapping
    public R chatHistory(){
        Long userId = SecurityUtils.getUserId();
        QueryWrapper<ChatHistory> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ChatHistory::getUserId,userId)
                .orderByDesc(ChatHistory::getCreateTime)
                .last("limit 10");
        List<ChatHistory> list = chatHistoryService.list(queryWrapper);
        return R.ok(list);
    }

}
